package com.mygdx.game.font;


import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.viewport.StretchViewport;


public class FontShow extends ApplicationAdapter {
    private FreeFont freeFont;
    private Stage stage;
    private BitmapFont font;

    public FontShow(FreeListener freeListener) {
        freeFont = new FreeFont(freeListener);
    }

    public void create() {
        stage = new Stage(new StretchViewport(480, 800));
        stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
        Gdx.input.setInputProcessor(stage);

//
        font = freeFont.getFont("默认字体");// 初始化字符
        Label label = new Label("默认字体", new LabelStyle(font, Color.WHITE));
        label.setY(770);
        stage.addActor(label);
// 变色
        freeFont.appendChars(font, "红色字体 ");// 动态增加字符
        Label label2 = new Label("红色字体", label.getStyle());
        label2.setColor(Color.RED);// 普通的变色可以考虑改变Label的Color，而不是直接创建一个不同的BitmapFont
        label2.setPosition(label.getRight(), label.getY());
        stage.addActor(label2);
// 缩小字号
        freeFont.appendChars(font, "绿色小号字体");
        Label label3 = new Label("绿色小号字体", label.getStyle());
        label3.setColor(Color.GREEN);
        label3.setFontScale(0.8f);// 普通的缩小可以考虑改变Label的setFontScale
        label3.setSize(label3.getPrefWidth(), label3.getPrefHeight());// 需要注意的是缩放后label的控件宽高没有自动缩放
        label3.setPosition(label2.getRight(), label2.getY());
        stage.addActor(label3);
// 缩小字号

        FreePaint freePaint=new FreePaint();
        freePaint.setTextSize(100);
        freePaint.setStrokeColor(Color.GREEN);
        freePaint.setStrokeWidth(1);
        freePaint.setFakeBoldText(true);
        font=freeFont.getFont(freePaint, "FPS:"+ Gdx.graphics.getFramesPerSecond());
        Label label4 = new Label("FPS:" + Gdx.graphics.getFramesPerSecond(),new LabelStyle(font,Color.CYAN));
        label4.setFontScale(1.0f);// 普通的缩小可以考虑改变Label的setFontScale
        label4.setSize(label4.getPrefWidth(), label4.getPrefHeight());// 需要注意的是缩放后label的控件宽高没有自动缩放
        label4.setPosition(0, label4.getY());
        stage.addActor(label4);
    }

    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act();
        create();
        stage.draw();
    }
}